<?php
	define("APP_KEY", '12448045');
	define("APP_SECRET", '78fb9dc00403611540c8fd0e5ba35382');
	function Product_Cat()
	{
		return array('1'=>'衣服', '2'=>'鞋子', '8'=>'包包', '3'=>'美妆', '4'=>'母婴', '5'=>'食品', '6'=>'居家', '9'=>'配饰', '7'=>'其他');
	}

	function Store_Cat()
	{
		return array('1'=>'女装', '2'=>'男装', '3'=>'女鞋', '4'=>'男鞋', '5'=>'运动', '6'=>'手机', '7'=>'箱包', '8'=>'内衣', '9'=>'化妆品', '10'=>'母婴', '11'=>'数码', '12'=>'食品&保健', '13'=>'居家生活', '14'=>'配件');
	}

	/**
	 * 获取请求ip
	 *
	 * @return ip地址
	 */
	function ip() {
		if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
			$ip = getenv('HTTP_CLIENT_IP');
		} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
			$ip = getenv('HTTP_X_FORWARDED_FOR');
		} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
			$ip = getenv('REMOTE_ADDR');
		} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
			$ip = $_SERVER['REMOTE_ADDR'];
		}
		return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
	}

	function time_tran($the_time)
	{
		$now_time = date("Y-m-d H:i:s");
		$now_time = strtotime($now_time);
		$show_time = strtotime($the_time);
		$dur = $now_time - $show_time;
		if($dur < 60){
			return $dur.'秒前';
		}else{
			if($dur < 3600){
				return floor($dur/60).'分钟前';
			}else{
				if($dur < 86400){
					return floor($dur/3600).'小时前';
				}else{
					if($dur < 259200){//3天内
						return floor($dur/86400).'天前';
					}else{
						return $the_time;
					}	
				}
			}
		}
	}

	function sub_cname($value)
	{
		if(strlen($value) > 20) {
			return substr($value, 0, strrpos($value, '/'));
		}
		return $value;
	}

	function datetoch($the_date)
	{
		$date = explode('-', $the_date);
		return intval($date[1]) . '月' . intval($date[2]) . '日';
	}